//
//  GSSObject.h
//  iGSS
//
//  Copyright 2010 Electronic Business Systems Ltd.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#import <UIKit/UIKit.h>

typedef enum {
    GSSObjectTypeHome,
    GSSObjectTypeRoot,
    GSSObjectTypeFolder,
    GSSObjectTypeFile,
    GSSObjectTypeShared,
    GSSObjectTypeOthers,
    GSSObjectTypeTrash,
    GSSObjectTypeUser,
    GSSObjectTypeTags,
    GSSObjectTypeGroups,
    GSSObjectTypeQuery,
} GSSObjectType;

extern const char *GSSAcessDateAttr;

@interface GSSObject : NSObject {
    NSMutableDictionary *meta;
    NSMutableArray *children;

    NSString *uri;
    GSSObjectType type;
    NSInteger error;
    GSSObject *referer;

    BOOL uploading;
    BOOL childrenUpdated;    
}

@property (nonatomic, readonly) NSDictionary *meta;
@property (nonatomic, readonly) NSMutableArray *children;

@property (nonatomic, copy) NSString *uri;
@property (nonatomic, assign) GSSObjectType type;
@property (nonatomic, assign) NSInteger error;
@property (nonatomic, retain) GSSObject *referer;

@property (nonatomic, assign) BOOL uploading;
@property (nonatomic, assign) BOOL childrenUpdated;

@property (nonatomic, retain) NSString *name;
@property (nonatomic, assign) unsigned long long size;
@property (nonatomic, assign) NSInteger version;
@property (nonatomic, assign) BOOL versioned;
@property (nonatomic, assign) BOOL readForAll;
@property (nonatomic, assign) BOOL deleted;
@property (nonatomic, retain) NSArray *tags;
@property (nonatomic, retain) NSArray *permissions;
@property (nonatomic, retain) NSString *content;
@property (nonatomic, retain) NSDate *fetchDate;

@property (nonatomic, readonly) NSString *path;
@property (nonatomic, readonly) NSString *owner;
@property (nonatomic, readonly) NSString *createdBy;
@property (nonatomic, readonly) NSString *modifiedBy;
@property (nonatomic, readonly) NSDate *creationDate;
@property (nonatomic, readonly) NSDate *modificationDate;

@property (nonatomic, readonly) BOOL isEmpty;
@property (nonatomic, readonly) BOOL isPartial;
@property (nonatomic, readonly) BOOL isStale;
@property (nonatomic, readonly) BOOL isShared;
@property (nonatomic, readonly) BOOL hasExpiredData;

@property (nonatomic, readonly) NSData *data;
@property (nonatomic, readonly) UIImage *icon;
@property (nonatomic, readonly) GSSObject *parent;

@property (nonatomic, readonly) NSString *metaCachePath;
@property (nonatomic, readonly) NSString *dataCachePath;

- (id)initWithURI:(NSString *)aURI withType:(GSSObjectType)aType;

- (void)updateMeta:(NSDictionary *)newMeta;
- (void)addChild:(GSSObject *)child;
- (void)removeChild:(GSSObject *)child;
- (void)load;
- (void)save;
- (void)saveData:(NSData *)someData;
- (void)delete;
- (void)updateMetaAccessDate;
- (void)updateDataAccessDate;

- (NSString *)uriForVersion:(NSInteger)aVersion;

@end
